fix: rival apply/#658#667
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a unique database constraint to prevent duplicate rival records and includes a migration script to clean up existing entries. It also adds error handling for integrity violations during the rival application process. The review feedback highlights that the manual mirror-record cleanup logic in the service and repository layers is now redundant due to the new database constraint and should be removed. Additionally, the reviewer pointed out that the GetMyRivalActingServiceTest class was improperly disabled by being commented out and must be restored.
redjungi09
approved these changes
Apr 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
변경사항
rivals테이블에uq_rivals_active_pairunique partial index 추가 (LEAST/GREATEST로 방향 정규화, PENDING/ACCEPTED 상태만 적용)AcceptRivalService.cancelMirrorPendingIfExists)ApplyRivalService에서 DB constraint 위반 시DataIntegrityViolationException→AlreadyAppliedRivalException(500 → 409) 변환관련 이슈
Closes #658
추가 컨텍스트
레이스 컨디션 발생 조건
PostgreSQL 기본 격리 수준(READ COMMITTED)에서 A→B, B→A 신청이 동시에 들어오면
existsActiveRivalBetween체크가 두 트랜잭션 모두 통과해 중복 레코드가 생성됨.방어 레이어
1차 (애플리케이션): existsActiveRivalBetween 체크 (기존)
↓ 레이스 컨디션으로 뚫릴 경우
2차 (DB): uq_rivals_active_pair 인덱스가 INSERT 거부
↓ 거부 시
3차 (예외 변환): DataIntegrityViolationException → AlreadyAppliedRivalException (409)
마이그레이션 주의사항
user_notices.rival_id의 FK가ON DELETE SET NULL이므로 rivals 삭제 전 notices를 먼저 삭제 (orphan notice 방지). Step 1 → Step 2 → Step 3 순차 실행, 단일 트랜잭션으로 실패 시전체 롤백.